package com.itboye.sunsun.adapter;

import java.util.Date;
import java.util.List;

import com.itboye.sunsun.R;
import com.itboye.sunsun.application.App;
import com.itboye.sunsun.beans.MessageBean;
import com.itboye.sunsun.constants.NetPublicConstant;
import com.itboye.sunsun.utils.LongParse;
import com.itboye.sunsun.utils.XImageLoader;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class OrderAnnounceAdapter extends BaseAdapter {

	 
	List<MessageBean> dataList;
	public OrderAnnounceAdapter(List<MessageBean> dataList ) {
	 
		this.dataList=dataList;
	}

	@Override
	public int getCount() {
		
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		
		return null;
	}

	@Override
	public long getItemId(int position) {
		
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView==null) {
			convertView=LayoutInflater.from(App.ctx).inflate(R.layout.item_system_announce	, null);
			holder=new ViewHolder();
			holder.time=(TextView) convertView.findViewById(R.id.time);
			holder.title=(TextView) convertView.findViewById(R.id.title);
			holder.summery=(TextView) convertView.findViewById(R.id.summery);
			
			holder.iv=(ImageView) convertView.findViewById(R.id.iv);
			holder.more=(TextView) convertView.findViewById(R.id.more);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		MessageBean bean=dataList.get(position);
		holder.time.setText(new Date(LongParse.parse(bean.getCreateTime(), 0)*1000).toLocaleString());
		holder.title.setText(bean.getTitle());
		holder.summery.setText(bean.getSummary());
		if (bean.getExtra()!=null) {
			holder.summery.append("\n");
			holder.summery.append(bean.getExtra().getOrderCode());
			XImageLoader.load(NetPublicConstant.IMAGE_URL+bean.getExtra().getImage(), holder.iv);
		}
		
		return convertView;
	}

	class ViewHolder{
		TextView time;
		TextView title;
		TextView summery;
		ImageView iv;
		TextView more;
	}
}
